package com.weepal.pavement.mqtt.demo.controller;

import com.weepal.pavement.mqtt.demo.config.dataSource.DataSourceConfig;
import com.weepal.pavement.mqtt.demo.config.dataSource.TargetSource;
import com.weepal.pavement.mqtt.demo.service.MqttDevicesService;
import com.weepal.pavement.mqtt.demo.vo.MqttDevices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/device")
@Slf4j
public class MqttDevicesController {
    @Autowired
    private MqttDevicesService service;

    @PostMapping("add")
    public void add(@RequestBody MqttDevices mqttDevices) {
        mqttDevices.setKid(UUID.randomUUID().toString().replace("-", ""));
        service.save(mqttDevices);
    }

    @PostMapping("update")
    public void update(@RequestBody MqttDevices mqttDevices) {
        service.updateById(mqttDevices);
    }

    @PostMapping("delete")
    public void delete(@RequestBody MqttDevices mqttDevices) {
        mqttDevices.setIsDel(1);
        service.updateById(mqttDevices);
    }

    /**
     * 过滤已删除的(isDel = 0)
     * projId 项目id 非必传
     * pactId 标段id 非必传
     */
    @PostMapping("getList")
    public void getList(@RequestParam Map<String, Object> map) {
        service.getList(map);
    }

}
